import { GCheckBox } from "../../../../com/mui/controls/GCheckBox";
import { Language } from "../../../../extend/language/Language";
import { Cache } from "../../cache/Cache";
import { FilterConst } from "../../../component/gconst/FilterConst";
import { GButton } from "../../../../com/mui/controls/GButton";
import { GLabel } from "../../../../com/mui/controls/GLabel";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { GTextFormat } from "../../../common/GTextFormat";
import { GTextInput } from "../../../../com/mui/controls/GTextInput";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { Game } from "../../Game";
import { TaskTargetInfo } from "../../model/TaskTargetInfo";
import { EntityType } from "../../rules/EntityType";
//class CurrentUnitChange
    
    export  class CurrentUnitChange /* flash.display.Sprite */
    {
        constructor()
        {
            
            this.initUI();
            return;
        }

        /* internal  */initUI(): void
        {
            this._displayArea = new GCheckBox();
            this._displayArea.label = Language.getStringByParam(20633, Language.getString(20634));
            this._displayArea.styleName = "GCheckBox";
            this._displayArea.selected = Cache.instance.mapui.showArea;
            this._displayArea.buttonMode = true;
            this._displayArea.mouseChildren = false;
            this._displayArea.x = 0;
            this._displayArea.y = 11;
            this._displayArea.textField.filters = [FilterConst.nameGlowFilter];
            this._displayArea.addEventListener(flash.events.Event.CHANGE, this.onDisplayAreaChange, false, 0, true);
            addChild(this._displayArea);
            this._displayMonster = new GCheckBox();
            this._displayMonster.label = Language.getStringByParam(20633, Language.getString(20635));
            this._displayMonster.styleName = "GCheckBox";
            this._displayMonster.selected = Cache.instance.mapui.showBoss;
            this._displayMonster.buttonMode = true;
            this._displayMonster.mouseChildren = false;
            this._displayMonster.x = 80;
            this._displayMonster.y = 11;
            this._displayMonster.textField.filters = [FilterConst.nameGlowFilter];
            this._displayMonster.addEventListener(flash.events.Event.CHANGE, this.onDisplayMonsterChange, false, 0, true);
            addChild(this._displayMonster);
            this._displayNPC = new GCheckBox();
            this._displayNPC.label = Language.getStringByParam(20633, "NPC");
            this._displayNPC.styleName = "GCheckBox";
            this._displayNPC.selected = Cache.instance.mapui.showNpc;
            this._displayNPC.buttonMode = true;
            this._displayNPC.mouseChildren = false;
            this._displayNPC.x = 160;
            this._displayNPC.y = 11;
            this._displayNPC.textField.filters = [FilterConst.nameGlowFilter];
            this._displayNPC.addEventListener(flash.events.Event.CHANGE, this.onDisplayNPCChange, false, 0, true);
            addChild(this._displayNPC);
            this._toGoBtn = new GButton();
            this._toGoBtn.styleName = "Button";
            this._toGoBtn.x = 400;
            this._toGoBtn.y = 10;
            this._toGoBtn.width = 70;
            this._toGoBtn.height = 22;
            this._toGoBtn.label = Language.getString(20636);
            this._toGoBtn.textField.filters = [FilterConst.nameGlowFilter];
            this._toGoBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onToGo, false, 0, true);
            addChild(this._toGoBtn);
            this._xDesc = new GLabel();
            this._xDesc.x = 485;
            this._xDesc.y = 2;
            this._xDesc.htmlText = HTMLUtil.addColor("X:", "#b2f0fd");
            this._xDesc.textField.filters = [FilterConst.nameGlowFilter];
            this._xDesc.textField.defaultTextFormat = new GTextFormat("", 14);
            addChild(this._xDesc);
            this._xInput = new GTextInput();
            this._xInput.maxChars = 3;
            this._xInput.x = 505;
            this._xInput.y = 0;
            this._xInput.width = 50;
            this._xInput.height = 22;
            this._xInput.styleName = "GTextInput";
            this._xInput.restrict = "0-9";
            addChild(this._xInput);
            this._yDesc = new GLabel();
            this._yDesc.x = 485;
            this._yDesc.y = 26;
            this._yDesc.textField.filters = [FilterConst.nameGlowFilter];
            this._yDesc.htmlText = HTMLUtil.addColor("Y:", "#b2f0fd");
            this._yDesc.textField.defaultTextFormat = new GTextFormat("", 14);
            addChild(this._yDesc);
            this._yInput = new GTextInput();
            this._yInput.maxChars = 3;
            this._yInput.x = 505;
            this._yInput.y = 22;
            this._yInput.width = 50;
            this._yInput.height = 22;
            this._yInput.restrict = "0-9";
            this._yInput.styleName = "GTextInput";
            addChild(this._yInput);
            return;
        }

        /* internal  */onDisplayMissionChange(arg1: Object /* flash.events.Event */): void
        {
            Cache.instance.mapui.showTask = this._displayMission.selected;
            dispatchEvent(new DataEvent(EventName.MapUIDisplayChange));
            return;
        }

        /* internal  */onDisplayMonsterChange(arg1: Object /* flash.events.Event */): void
        {
            Cache.instance.mapui.showBoss = this._displayMonster.selected;
            dispatchEvent(new DataEvent(EventName.MapUIDisplayChange));
            return;
        }

        /* internal  */onDisplayAreaChange(arg1: Object /* flash.events.Event */): void
        {
            Cache.instance.mapui.showArea = this._displayArea.selected;
            dispatchEvent(new DataEvent(EventName.MapUIDisplayChange));
            return;
        }

        /* internal  */onDisplayNPCChange(arg1: Object /* flash.events.Event */): void
        {
            Cache.instance.mapui.showNpc = this._displayNPC.selected;
            dispatchEvent(new DataEvent(EventName.MapUIDisplayChange));
            return;
        }

        /* internal  */onToGo(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=int(this._xInput.text);
            var loc2=int(this._yInput.text);
            var loc3=Game.mapInfo.gridXNum;
            var loc4=Game.mapInfo.gridYNum;
            loc1 = loc1 < 0 ? 0 : loc1 > Game.mapInfo.gridXNum ? (Game.mapInfo.gridXNum - 1) : loc1;
            loc2 = loc2 < 0 ? 0 : loc2 > Game.mapInfo.gridYNum ? (Game.mapInfo.gridYNum - 1) : loc2;
            if (!this._autoPathTarget) 
            {
                this._autoPathTarget = new TaskTargetInfo();
            }
            this._autoPathTarget.x = loc1;
            this._autoPathTarget.y = loc2;
            this._autoPathTarget.targetType = EntityType.Point;
            dispatchEvent(new DataEvent(EventName.MapUIAutoPathByPoint, this._autoPathTarget));
            return;
        }

        public set optEnabled(arg1: Boolean)
        {
            return;
        }

        protected /* var */_xDesc: GLabel;

        protected /* var */_xInput: GTextInput;

        protected /* var */_yDesc: GLabel;

        protected /* var */_yInput: GTextInput;

        protected /* var */_toGoBtn: GButton;

        protected /* var */_displayNPC: GCheckBox;

        protected /* var */_displayMission: GCheckBox;

        protected /* var */_displayMonster: GCheckBox;

        protected /* var */_displayArea: GCheckBox;

        /* internal */ /* var */_autoPathTarget: TaskTargetInfo;
    }
